﻿using System.Runtime.Serialization;
using System.Windows;
using Foundation;
using Poet.Modules;

namespace Poet.ViewModels
{
    /// <summary>
    /// FontViewModel.
    /// </summary>
    [DataContract]
    internal class FontSetViewModel : DocumentSettingsViewModel<FontSet>
    {
        public FontSetViewModel()
        {
            Initialize();
        }

        protected override sealed FontSet GetFactorySettings()
        {
            return
                new FontSet
                    {
                        Name = "Factory",
                        FontFamily = "Consolas",
                        FontSize = 40.0/3.0,
                        FontStretch = FontStretches.Normal,
                        FontStyle = FontStyles.Normal,
                        FontWeight = FontWeights.Normal,
                    };
        }

        [OnDeserialized]
        private void Initialize(StreamingContext context = default(StreamingContext))
        {
            ApplicationClosing += () => this.TrySerializeDataContract();
            GetSettingsAction += model => model.TextEditorViewModel.GetFont();
            SetSettingsAction += (model, font) => model.TextEditorViewModel.SetFont(font);
        }
    }
}
